package com.example.boot3.rpc.calculation;

public class TestCalc {
    /*private static final JexlEngine jexl = new JexlBuilder()
            .cache(512) // 缓存表达式提高性能
            .strict(true) // 严格模式
            .create();

    *//**
     * 从数据库加载公式表达式
     *//*
    public static Object calculateFormula(String formulaExpression, Map<String, Object> variables) {
        try {
            // 创建表达式
            JexlExpression expression = jexl.createExpression(formulaExpression);

            // 创建上下文并设置变量
            JexlContext context = new MapContext();
            for (Map.Entry<String, Object> entry : variables.entrySet()) {
                context.set(entry.getKey(), entry.getValue());
            }

            // 添加数学常量
            context.set("PI", Math.PI);
            context.set("E", Math.E);

            // 执行计算
            return expression.evaluate(context);

        } catch (JexlException e) {
            throw new RuntimeException("公式解析错误: " + e.getMessage(), e);
        }
    }


    *//**
     * 批量计算公式（适用于多条数据）
     *//*
    public Map<String, Object> batchCalculate(String formulaExpression,
                                              Map<String, Object>[] dataList) {
        Map<String, Object> results = new HashMap<>();

        for (int i = 0; i < dataList.length; i++) {
            try {
                Object result = calculateFormula(formulaExpression, dataList[i]);
                results.put("result_" + i, result);
            } catch (Exception e) {
                results.put("error_" + i, e.getMessage());
            }
        }

        return results;
    }*/
}

